/**
 * 具体工作流 API 接口
 * 为每个工作流提供专门的 API 方法
 */

import { workflowApi, type WorkflowParams } from './workflowApi'
import { type TaskProgressResponse, type TaskResultResponse } from './lightcc-api'

// SPA生图（手写提示词）API
export class SpaTextApi {
  static async generateImage(
    prompt: string,
    options: {
      negativePrompt?: string
      width?: number
      height?: number
      steps?: number
      cfg?: number
      seed?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      prompt,
      negativePrompt: options.negativePrompt,
      width: options.width || 1024,
      height: options.height || 1024,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0,
      seed: options.seed
    }

    return await workflowApi.executeWorkflow('spa-text', params, options.onProgress)
  }
}

// SPA生图（风格参考）API
export class SpaStyleApi {
  static async generateImage(
    prompt: string,
    styleImage: File,
    options: {
      negativePrompt?: string
      width?: number
      height?: number
      steps?: number
      cfg?: number
      seed?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      prompt,
      styleImage,
      negativePrompt: options.negativePrompt,
      width: options.width || 1024,
      height: options.height || 1024,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0,
      seed: options.seed
    }

    return await workflowApi.executeWorkflow('spa-style', params, options.onProgress)
  }
}

// 光线修改 API
export class LightModifyApi {
  static async modifyLight(
    inputImage: File,
    options: {
      prompt?: string
      intensity?: number
      temperature?: number
      contrast?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      inputImage,
      prompt: options.prompt || '调整光线效果',
      intensity: options.intensity || 1.0,
      temperature: options.temperature || 0.0,
      contrast: options.contrast || 1.0
    }

    return await workflowApi.executeWorkflow('light-modify', params, options.onProgress)
  }
}

// 单图指令编辑 API
export class SingleEditApi {
  static async editImage(
    inputImage: File,
    prompt: string,
    options: {
      negativePrompt?: string
      strength?: number
      steps?: number
      cfg?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      inputImage,
      prompt,
      negativePrompt: options.negativePrompt,
      strength: options.strength || 0.8,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0
    }

    return await workflowApi.executeWorkflow('single-edit', params, options.onProgress)
  }
}

// 双图编辑参考风格 API
export class DoubleEditApi {
  static async editWithStyle(
    inputImage: File,
    styleImage: File,
    prompt: string,
    options: {
      negativePrompt?: string
      styleStrength?: number
      steps?: number
      cfg?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      inputImage,
      styleImage,
      prompt,
      negativePrompt: options.negativePrompt,
      styleStrength: options.styleStrength || 0.8,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0
    }

    return await workflowApi.executeWorkflow('double-edit', params, options.onProgress)
  }
}

// 台球生图（手写提示词）API
export class BilliardsTextApi {
  static async generateImage(
    prompt: string,
    options: {
      negativePrompt?: string
      width?: number
      height?: number
      steps?: number
      cfg?: number
      seed?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      prompt,
      negativePrompt: options.negativePrompt,
      width: options.width || 1024,
      height: options.height || 1024,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0,
      seed: options.seed
    }

    return await workflowApi.executeWorkflow('billiards-text', params, options.onProgress)
  }
}

// 台球生图（风格参考）API
export class BilliardsStyleApi {
  static async generateImage(
    prompt: string,
    styleImage: File,
    options: {
      negativePrompt?: string
      width?: number
      height?: number
      steps?: number
      cfg?: number
      seed?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      prompt,
      styleImage,
      negativePrompt: options.negativePrompt,
      width: options.width || 1024,
      height: options.height || 1024,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0,
      seed: options.seed
    }

    return await workflowApi.executeWorkflow('billiards-style', params, options.onProgress)
  }
}

// 图生视频 API
export class ImageToVideoApi {
  static async generateVideo(
    inputImage: File,
    options: {
      prompt?: string
      videoLength?: number
      fps?: number
      motionStrength?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      inputImage,
      prompt: options.prompt || '生成视频',
      videoLength: options.videoLength || 3,
      fps: options.fps || 24,
      motionStrength: options.motionStrength || 1.0
    }

    return await workflowApi.executeWorkflow('image-to-video', params, options.onProgress)
  }
}

// 局部重绘 API
export class InpaintingApi {
  static async inpaint(
    inputImage: File,
    maskImage: File,
    prompt: string,
    options: {
      negativePrompt?: string
      strength?: number
      steps?: number
      cfg?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      inputImage,
      maskImage,
      prompt,
      negativePrompt: options.negativePrompt,
      strength: options.strength || 0.8,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0
    }

    return await workflowApi.executeWorkflow('inpainting', params, options.onProgress)
  }
}

// 瑜伽生图（手写提示词）API
export class YogaTextApi {
  static async generateImage(
    prompt: string,
    options: {
      negativePrompt?: string
      width?: number
      height?: number
      steps?: number
      cfg?: number
      seed?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      prompt,
      negativePrompt: options.negativePrompt,
      width: options.width || 1024,
      height: options.height || 1024,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0,
      seed: options.seed
    }

    return await workflowApi.executeWorkflow('yoga-text', params, options.onProgress)
  }
}

// 瑜伽生图（风格参考）API
export class YogaStyleApi {
  static async generateImage(
    prompt: string,
    styleImage: File,
    options: {
      negativePrompt?: string
      width?: number
      height?: number
      steps?: number
      cfg?: number
      seed?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      prompt,
      styleImage,
      negativePrompt: options.negativePrompt,
      width: options.width || 1024,
      height: options.height || 1024,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0,
      seed: options.seed
    }

    return await workflowApi.executeWorkflow('yoga-style', params, options.onProgress)
  }
}

// 迁移 API
export class MigrationApi {
  static async migrateStyle(
    inputImage: File,
    styleImage: File,
    options: {
      prompt?: string
      styleStrength?: number
      steps?: number
      cfg?: number
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      inputImage,
      styleImage,
      prompt: options.prompt || '风格迁移',
      styleStrength: options.styleStrength || 0.8,
      steps: options.steps || 20,
      cfg: options.cfg || 7.0
    }

    return await workflowApi.executeWorkflow('migration', params, options.onProgress)
  }
}

// 高清放大（gemini）API
export class UpscaleGeminiApi {
  static async upscaleImage(
    inputImage: File,
    options: {
      scaleFactor?: number
      modelName?: string
      onProgress?: (progress: TaskProgressResponse) => void
    } = {}
  ): Promise<TaskResultResponse> {
    const params: WorkflowParams = {
      inputImage,
      scaleFactor: options.scaleFactor || 2,
      modelName: options.modelName || '003_realSR_BSRGAN_DFOWMFC_s64w8_SwinIR-L_x4_GAN.pth'
    }

    return await workflowApi.executeWorkflow('upscale-gemini', params, options.onProgress)
  }
}

